
const express = require('express');
let Router = express.Router();

let mysql = require('../sql')

module.exports = Router;

// http://localhost:3000/user/api/login
// 登录接口
Router.post('/api/login', (req, res) => {
    let { username, password } = req.query;

    mysql.sql({
        sql: `select * from user WHERE username='${username}' AND password='${password}';`,

        success(results) {
            console.log(1);
            if (results.length == 0) {
                res.send({
                    code: 400,
                    msg: '用户名或者密码错误'
                })
                return
            }
            res.send({
                code: 200,
                data: results[0],
                msg: '登录成功'
            })
        },
        error(err) {
            res.send(err)
        }
    })
})


Router.use(express.json(), express.urlencoded())

// 注册接口
Router.post('/api/reg', (req, res) => {
    let { username, password } = req.body
    res.send({
        code: 200,
        msg: '注册接口'
    })
})


Router.get('/api/user/check', (req, res) => {
    res.send({
        code: 200,
        msg: '判断用户是否存在'
    })
})